package com.ddpyjqtd.proxy.cglib;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * @Description: cglib代理类
 * 
 * @author: ddpyjqtd
 * @Date: 2019年3月11日
 *
 */
public class CglibProxy implements MethodInterceptor {

	public Object getInstance(Object target) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(target.getClass());
		enhancer.setCallback(this);
		return enhancer.create();
	}

	@Override
	public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
		
		System.out.println("...这里是cglib的代理，提出你的需求");
		Object invokeSuper = arg3.invokeSuper(arg0, arg2);
		System.out.println(".......已接受委托，请等待，客服会联系您。。。");
		
		return invokeSuper;
	}

}
